﻿using System;
using Autodesk.Revit.DB;
using YJKDimensionModel.LevelDimension;
using YJKRGeometry;
using SectionSignAndFilled.StairsRoomPlanSign.ControlLayer;

namespace SectionSignAndFilled.StairsRoomPlanSign.ModelLayer
{
	public class LevelDimensionPacker : IDimensionMake
	{
		public double UseElevation
		{
			get
			{
				return this.m_useElevation;
			}
			private set
			{
				this.m_useElevation = value;
			}
		}

		public LevelDimensionPacker(XYZ inputLocation, double inputElevation)
		{
			this.m_useLocation = inputLocation;
			this.UseElevation = inputElevation;
		}

		public bool TryMakeSign(Document inputDoc, ViewPlan useView)
		{
			bool result;
			try
			{
				LevelDimensionManager levelDimensionManager = new LevelDimensionManager(SignManger.CommandData);
				FamilyInstance familyInstance = levelDimensionManager.CreateSymbolFamily(this.m_useLocation, useView, null, this.UseElevation, true, "符号_普通标高(右上).rfa");
				double num = SignManger.ThisStairPlandDataPacker.UseView.RightDirection.AngleTo(XYZ.BasisX);
				if (Geometry.LessThan(SignManger.ThisStairPlandDataPacker.UseView.RightDirection.Y, 0.0))
				{
					num = -num;
				}
				ElementTransformUtils.RotateElement(inputDoc, familyInstance.Id, Line.CreateUnbound(this.m_useLocation, XYZ.BasisZ), num);
				result = true;
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		private XYZ m_useLocation;

		private double m_useElevation;
	}
}
